import 'package:flutter/material.dart';
import 'package:flutter_enjoy_plus/pages/login/index.dart';
import 'package:flutter_enjoy_plus/pages/notice/index.dart';
import 'package:flutter_enjoy_plus/pages/profile/index.dart';
import 'package:flutter_enjoy_plus/pages/tabs_page.dart';
import 'package:flutter_enjoy_plus/utils/TokenManager.dart';

void main() {
  runApp(MaterialApp(
    routes: {
      "/": (context) => const TabsPage(),
      '/detail': (context) => const NoticeDetail(),
      '/login': (context) => const LoginPage(),
    },
    initialRoute: "/", // 默认路由 第一个页面访问哪一个 ability中 loadContent()

    onGenerateRoute: (setting) {
      var token = tokenManager.getToken();
      if (token.isEmpty) {
        return MaterialPageRoute(builder: (context) => const LoginPage());
      } else {
        if (setting.name == '/profile') {
          return MaterialPageRoute(builder: (context) => const ProfilePage());
        }
      }
      return null;
    },
  ));
}
